# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        last_val = None
        pre_node = ListNode(None)
        res = head
        while head:
            if head.val != last_val:
                pre_node = head
                last_val = head.val
            else:
                pre_node.next = head.next
            head = head.next
        return res


a1 = ListNode(1)
a2 = ListNode(1)
a3 = ListNode(1)
a1.next = a2
a2.next = a3
s = Solution()
node = s.deleteDuplicates(a1)
while node:
    print(node.val)
    node = node.next
